package com.zegome.game.gomestory.main.helper;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.zegome.game.gomestory.main.scene.BaseGameScreen;

public class MTable extends Table{
	
	BaseGameScreen screen;
	
	public void setScreen(BaseGameScreen screen){
		this.screen = screen;	
	}
	
	int x,y, wi, hi;
	IMAction lis;
	
	public void setInfo(int x, int y, int wi, int hi, IMAction lis)
	{
		this.x = x;
		this.y = y;
		this.wi = wi;
		this.hi = hi;
		this.lis = lis;
	}
	
	Vector3 touch = new Vector3();
	
	void configPosition(final Vector3 vector, final float x, final float y) {
		vector.set(x, y, 0);
		screen.getCamera().unproject(vector);
	}
		
	@Override
	public void act(float arg0) {
		
		if (Gdx.input.justTouched()) 
		{			
			float xTouch, yTouch;
			
			configPosition(touch, Gdx.input.getX(), Gdx.input.getY());			
			xTouch = touch.x;
			yTouch = touch.y;	
			
			//System.out.println(xTouch+"-"+yTouch);
			
			if(xTouch<x || xTouch>x+wi||yTouch<y || yTouch>y+hi){
			
					lis.action();					
				
			}
		}
		super.act(arg0);
	}
}
